/*
 * @(#)ClassificationNodeTransformer.java
 * Date 2013-09-05
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.registry.transformer.model;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import oasis.names.tc.ebxml_regrep.xsd.rim._3.ClassificationType;

import org.apache.commons.lang3.StringUtils;

import us.hornerscorners.lamppost.model.document.ClassificationNode;

import us.hornerscorners.lamppost.registry.utils.XDSUtils;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-09-05
 * @author         Jim Horner
 */
@ApplicationScoped
public class ClassificationNodeTransformer
        extends AbstractTransformer<ClassificationType, ClassificationNode> {

    /** Field description */
    @Inject
    private LocalizedStringTransformer localizedStringTransformer;

    /**
     * Constructs ...
     *
     */
    public ClassificationNodeTransformer() {
        super();
    }

    /**
     * Method description
     *
     *
     * @param ctype
     *
     * @return
     */
    @Override
    public ClassificationNode transform(ClassificationType ctype) {

        ClassificationNode result = new ClassificationNode();

        result.setEntryURN(XDSUtils.assignEntryUUID(ctype.getId()));
        result.setNodeURN(ctype.getClassificationNode());

        // versioning
        result.setEntryLogicalURN(StringUtils.defaultIfBlank(ctype.getLid(),
                result.getEntryURN()));
        result.setEntryVersion(
            StringUtils.defaultIfBlank(
                XDSUtils.parseVersionName(ctype.getVersionInfo()), "1"));

        result.getDisplayNames().addAll(
            this.localizedStringTransformer.transform(ctype.getName()));
        result.getDescriptions().addAll(
            this.localizedStringTransformer.transform(ctype.getDescription()));

        return result;
    }
}
